<template>
  <div class="error-page">
    <div class="error-container">
      <h1>401 - <span>Unauthorized</span></h1>
      <img class="minecraft-icon" src="@/assets/name_tag.png" alt="Nether Star">
      <p>You don't have permission to access this page</p>
      <p class="countdown-message">
        Redirecting to login page in <span class="countdown-number">{{ countdown }}</span> seconds...
      </p>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()
const countdown = ref(3)
let timer = null

const login = (immediate = false) => {
  router.push({
    path: '/login',
    query: { redirect: route.fullPath }
  })
}


onMounted(() => {
  timer = setInterval(() => {
    countdown.value--
    if (countdown.value <= 0) {
      clearInterval(timer)
      login()
    }
  }, 1000)
})

onBeforeUnmount(() => {
  clearInterval(timer)
})
</script>

<style scoped>
/* 基础重置 */
html, body, #app {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

.error-page {
  /* 视口设置 */
  height: 100vh;
  width: 100vw;
  overflow-y: auto;

  /* 布局设置 */
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #0a0a0a;
  color: white;
  font-family: Arial, sans-serif;
  padding: 20px;
  box-sizing: border-box;
}

.error-container {
  /* 内容容器 */
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.5rem;
  padding: 40px 20px;
}

.countdown-message {
  color: #aaa;
  font-size: 1rem;
  margin-top: 0.5rem;
}

.countdown-number {
  color: #44ffaa;
  font-weight: bold;
  font-size: 1.2rem;
}

h1 {
  font-size: 2.5rem;
  margin: 0;
  background: linear-gradient(90deg, #44ffaa, #4488ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

p {
  font-size: 1.1rem;
  color: #aaa;
  margin: 0;
  max-width: 600px;
}

.minecraft-icon {
  width: 150px;
  height: 150px;
  object-fit: contain;
  filter: drop-shadow(0 0 15px rgba(68, 255, 170, 0.5));
  animation: pulse 2s infinite;
}


button {
  padding: 12px 24px;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  border: none;
}


@keyframes pulse {
  0%, 100% { opacity: 0.8; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}

/* 响应式调整 */
@media (max-height: 700px) {
  .error-container {
    padding: 20px;
    gap: 1rem;
  }

  h1 {
    font-size: 2rem;
  }

  .minecraft-icon {
    width: 120px;
    height: 120px;
  }
}
</style>